home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / oxcc1434.zip / SRC / SKELETON.C < prev    next >
C/C++ Source or Header  |  1995-11-06  |  54KB  |  2,319 lines

  1. /* SKELETON.C -- THE PROTOTYPE APPLICATION FOR THE OXBOW FRAMEWORK
  2.     COMPILE WITH GCC
  3.  
  4.    COPYRIGHT 1994 Norman D. Culver, Ft. Lauderdale, FL
  5.  
  6. NOTE: 'main()' is at the end of the file.
  7. */
  8. #define SYMLINK(from,to) badsyms += oxlink_symlink(#from,#to)
  9.  
  10. #define EARLY_PRINT 1    /* set to 1 if trace before linkup needed */
  11.  
  12. #define BASE_CATEGORY 0
  13. #define MEMORY_BUG 0
  14. #define PRINT_RAWDATA 0
  15.  
  16. #if 0
  17. #define DPRINTF lprintf
  18. #else
  19. #define DPRINTF(args...)
  20. #endif
  21.  
  22. #if 0
  23. #define MPRINTF lprintf
  24. #else
  25. #define MPRINTF(args...)
  26. #endif
  27.  
  28. #if EARLY_PRINT == 1
  29. #define TPRINTF lprintf
  30. #else
  31. #define TPRINTF VPRINTF
  32. #endif
  33.  
  34. #include <go32.h>
  35.  
  36. /* extracts from 'oxbow.h' */
  37. typedef unsigned long long  KeyItem;   /* type for a key's associated item */
  38.  
  39. typedef union             /* 2 BYTES */
  40.     {
  41.         unsigned short val;
  42.         unsigned char b[2];
  43. } SVAL;
  44.  
  45. typedef union            /* 4 BYTES */
  46.     {
  47.     unsigned long a0;
  48.     void *a1;
  49.     struct
  50.         {
  51.         SVAL    lo_word;
  52.         SVAL    hi_word;
  53.         } a2;
  54.     struct
  55.         {
  56.             unsigned int pad :28;
  57.             unsigned int type :4;
  58.         } a3;
  59.     struct
  60.         {
  61.             unsigned char b[4];
  62.         } a4;
  63.     int a8;
  64.     short a9;
  65.     char a10;
  66.     float a11;
  67. } ADDR;
  68.  
  69. typedef union _stor    /* 8 BYTES */
  70.     {
  71.     unsigned long    a0;
  72.     void *a1;
  73.     KeyItem item;
  74.     struct
  75.         {
  76.         unsigned short    lo_word;
  77.         unsigned short    hi_word;
  78.         unsigned int size :28;        /* in bytes or nibbles */
  79.         unsigned int type :4;        /* describes the STOR type */
  80.         } a2;
  81.     struct
  82.         {
  83.             short s0;
  84.             short s1;
  85.             short s2;
  86.             short s3;
  87.         } a3;
  88.     struct
  89.         {
  90.             unsigned long    s0;
  91.             unsigned long    s1;
  92.         } a4;
  93.     struct
  94.         {
  95.             unsigned char    b[8];
  96.         } a5;
  97.     struct
  98.         {
  99.             unsigned long long dupname :48;
  100.             unsigned long long dupid :16;
  101.         } a6;
  102.     struct
  103.         {
  104.             unsigned int home : 30;
  105.             unsigned int full : 2;
  106.         } a7;
  107.     int a8;
  108.     short a9;
  109.     char a10;
  110.     float a11;
  111.     double a12;
  112. } STOR, Item;
  113.  
  114. typedef struct            /* 12 BYTES */
  115.     {
  116.         STOR c0;
  117.         ADDR c1;
  118. } CAT;
  119.  
  120. #define OB_XFILE    (0x00004000)
  121. #define OB_ROOTDIR    (0x00000200)
  122. #define OB_TREEDIR    (0x10000000)
  123. #define OB_HASHDIR    (0x20000000)
  124. #define F_RDONLY    (0x0001)
  125. #define F_STAT        (0x20000)    /* TRULY READONLY */
  126. #define O_RDONLY    (0x0001)
  127. #define O_BINARY    (0x8000)
  128. #define R_CLEAN        (0x40000000)
  129. #undef NULL
  130. #define NULL        ((void *)0)
  131. #define FOUND        (1)
  132. #define NODUPS        (0)
  133. #define S_SET        (0)
  134. #define S_READBLK    (1)
  135. #define S_WRITEBLK    (2)
  136.  
  137. #define    _cat2_(a, b)    a##b
  138. #define _cat_(a, b)    _cat2_(a, b)
  139. #define _qt2_(x) #x
  140. #define _qt_(x) _qt2_(x)
  141.  
  142. #define oxfunc(func, args...) ({ \
  143. typedef _fret = (appfunc()); \
  144. _fret (*dofunc)(); _fret _ret; \
  145. dofunc = oxlink_load_bare_symb(func,1); \
  146. if(dofunc) _ret = dofunc(## args) & 0x0fffffff; \
  147. else _ret = (_fret) -1; \
  148. _ret;})
  149.  
  150. #define oxload(func) \
  151. oxlink_load_bare_symb(_qt_(_cat_(_, func)),1)
  152.  
  153. #define oxunload(func) \
  154. oxlink_unload_symb(#func, 1)
  155.  
  156. typedef int jmp_buf[32];               /* an adequate buffer for setjmp */
  157. int setjmp();
  158. void longjmp();
  159.  
  160. /* end: extracts from 'oxbow.h' */
  161. /* ==================== A LIST OF PROBLEMS ======================= */
  162. /* external function prototypes needed initially,
  163.     THESE NEED TO BE LOCALIZED */
  164. void *sbrk();
  165. int open();
  166. int creat();
  167. int close();
  168. int read();
  169. int write();
  170. int lseek();
  171. char *getenv();
  172. char *getwd();
  173.  
  174. int strlen();
  175. char *strdup();
  176. char *strcat();
  177. char *strcpy();
  178. char *strchr();
  179. char *strrchr();
  180. char *strstr();
  181. int _strcpy();
  182. long strtol();
  183. int strcmp(const char *, const char *);
  184. int strncmp();
  185. void CF_Interactive_IO();
  186. int appfunc();
  187. void *malloc(unsigned);
  188. void *calloc(unsigned, unsigned);
  189. void free(void*);
  190. void *memcpy();
  191.  
  192. /* external function prototypes needed by the portability modules
  193.     THESE TOO NEED TO BE LOCALIZED (or something) */
  194. void exit();
  195. int ftruncate();
  196. void abort();
  197.  
  198. /* internal function prototypes */
  199. static int lnulfunc();
  200. static void lhash(void *, int, CAT *);
  201. static int laccess(char *, int);
  202. static int lpagesize(void);
  203. static int lprintchar(int);
  204. static void lprintstr(char *);
  205. static void lcrash(char *, ...);
  206. void CF_InitIO(long arg, long long (*msgproc)());
  207.  
  208. /* ======================== END LIST OF PROBLEMS ==================== */
  209.  
  210. /* DYNAMIC LINKER FUNCTIONS */
  211. int oxlink_init ();            /* initialize the routines */
  212. int oxlink_load_file ();    /* dynamically link and load an object file */
  213. int oxlink_load_object ();    /* link object file from libraries in list */
  214. void *oxlink_find_func ();    /* return the address of the named function */
  215. void *oxlink_find_bare_func ();/* same as oxlink_find_func except that
  216.                                no underscore (_) is prepended (also faster). */
  217. void * oxlink_find_sym ();    /* return the address of the named identifier  */
  218. void *oxlink_find_bare_symb ();/* same as oxlink_find_symb except that
  219.                                no underscore (_) is prepended (also faster). */
  220. int oxlink_unload_file ();   /* unlink a file */
  221. int oxlink_unload_symb (); /* unlink the module that defines the given symbol */
  222. int oxlink_unload_bare_symb (); /* unlink the module that defines the given symbol */
  223. char **oxlink_list_undefined_symb ();/* return an array of undefined symbols */
  224. char *cf_find_file ();/* return the full path name of the given file. */
  225. void *oxlink_load_symb(char *symb, int dynlink);
  226. void *oxlink_load_bare_symb(char *symb, int dynlink);
  227. int oxlink_export_symb();
  228. int oxlink_export_bare_symb();
  229. void oxlink_unexport_symb();
  230. void oxlink_unexport_bare_symb();
  231. int oxlink_symlink();            /* give new symbol same values as old symbol */
  232. void oxlink_demand_load();    /* define all undefined symbols with negative numbers */
  233. void oxlink_use_library();    /* add a filename for undefined symbol search */
  234. void oxlink_nouse_library();    /* remove a library from the search list */
  235. void  *oxlink_resolve_symb();    /* resolve one of the demand loadable undefs */
  236. void oxlink_trace();        /* set the trace level */
  237. char *oxlink_symname();        /* return name of a demand loadable undef */
  238. void *oxlink_rename_symb(char *old,char *new);
  239. int oxlink_rename_file(char *old,char *new);
  240. void oxlink_lib_check(int dynlink);    /* force search of library list */
  241. char *oxlink_file_of(char *symb);
  242. char *oxlink_file_of_bare(char *symb);
  243. int oxlink_scan_file(void *fhandle, void *thandle);
  244. void oxlink_set_libtype(int type);
  245. void oxlink_set_libnum(int libnum);
  246. void oxlink_load_thunk(int thunknum);
  247. int oxlink_prep_thunk(char *symb);
  248. void oxlink_clear_bss(char *filename);
  249. void *oxlink_get_entry_struct(char *filename);
  250. char *oxlink_errstr(void);
  251.  
  252. /* virtual function pointers initially hard linked to the load module */
  253. /* needed in order to initialize and read a .o or .a file */
  254. int (*VCFREAD)() = read;
  255. int (*VCFWRITE)() = write;
  256. void *(*VCFOPEN)() = (void *)open;
  257. int (*VCFCLOSE)() = close;
  258. int (*VCFLSEEK)() = lseek;
  259. int (*VACCESS)() = laccess;
  260. void *(*VSBRK)() = sbrk;
  261. char *(*VGETENV)() = getenv;
  262. char *(*VGETCWD)() = getwd;
  263. int (*VOBTYPE)() = lnulfunc;
  264.  
  265. void (*VHASH)() = lhash;
  266. int (*VGETPAGESIZE)() = lpagesize;
  267.  
  268.  
  269. #if EARLY_PRINT == 0
  270. int (*VVPRINTF)() = lnulfunc;
  271. int (*VSPRINTF)() = lnulfunc;
  272. int (*VPRINTF)() = lnulfunc;
  273. int (*BUGPRINTF)() = lnulfunc;
  274. #else
  275. static int lvprintf(char *, void *);
  276. static int lsprintf(char *, char *, ...);
  277. static int lprintf(char *, ...);
  278. int (*VVPRINTF)(char *, void*) = lvprintf;
  279. int (*VSPRINTF)(char *, char *, ...) = lsprintf;
  280. int (*VPRINTF)(char *, ...) = lprintf;
  281. int (*BUGPRINTF)(char *, ...) = lprintf;
  282. #endif
  283.  
  284. /* function pointers needed by portability modules */
  285. void *(*VMALLOC)() = malloc;
  286. void *(*VCALLOC)() = calloc;
  287. void (*VFREE)() = free;
  288. void (*VEXIT)() = exit;
  289. int (*VREAD)() = read;
  290. int (*VOPEN)() = open;
  291. int (*VCLOSE)() = close;
  292. int (*VLSEEK)() = lseek;
  293. int (*VWRITE)() = write;
  294. void (*VABORT)() = abort;
  295. int (*VPRINTCHAR)() = lprintchar;
  296. void (*VPRINTSTR)() = lprintstr;
  297. void (*VCRASH)(char* fmt, ...) = lcrash;
  298. void (*VBITBLT)();
  299. int (*VSTAT)() = lnulfunc;
  300.  
  301. /* function pointers used internally */
  302. int (*CFINIT)();
  303. void (*CFEXIT)();
  304. int (*COSINIT)();
  305. void (*THREADER)();
  306. void (*THREAD)();
  307. int *VINHIBIT_THREADER;
  308.  
  309. /* cff function pointers used but not available until cff is loaded */